package edu.fjut.se1603.yuan.service.impl;

import edu.fjut.se1603.yuan.dao.AccountDao;
import edu.fjut.se1603.yuan.dao.PetStoreDao;
import edu.fjut.se1603.yuan.dao.impl.AccountDaoImpl;
import edu.fjut.se1603.yuan.dao.impl.PetStoreDaoImpl;
import edu.fjut.se1603.yuan.service.PetStoreService;
import edu.fjut.se1603.yuan.util.CheckAccount;
import edu.fjut.se1603.yuan.util.KeyInput;

import javax.sound.midi.Soundbank;


public class PetStoreServiceImpl implements PetStoreService {

    private Integer StoreId;

    @Override
    public void login() {
        System.out.println("请输入姓名");
        String account = KeyInput.getString();
        System.out.println("请输入密码");
        String password = KeyInput.getString();
        while ((StoreId = CheckAccount.check("pet_store", account, password)) == null) {
            System.out.println("账户无效");
            if (KeyInput.getYON()) {
                System.out.println("请输入姓名");
                account = KeyInput.getString();
                System.out.println("请输入密码");
                password = KeyInput.getString();
            } else {
                return;
            }
        }
        System.out.println("-----恭喜你成功登录-----");
        menu();
    }

    //
//
    @Override
    public void getAccount(int storeId) {
        System.out.println("ID " + "宠物名 " + "主人名 " + "商店名 " + "交易类型 " + "交易时间");
        accountDao.getStoreAccount(storeId);
    }

    @Override
    public void addPet() {
        System.out.println("请输入宠物名：");
        String name=KeyInput.getString();
        System.out.println("请输入价格：");
        double price=KeyInput.getInt();
        if(petDao.addPet(name,price,StoreId)>0){
            System.out.println("宠物上线成功");
        }
    }

    @Override
    public void display() {
        petDao.getStorePet(StoreId);
    }

    private void menu() {
        System.out.println("请选择操作，查看订单输入1,上线宠物输入2，查看现有宠物输入3，退出系统输入4");
        switch (KeyInput.getInt()) {
            case 1:
                getAccount(StoreId);
                break;
            case 2:
                addPet();
                break;
            case 3:
                display();
                break;
            case 4:
                System.exit(0);
            default:
                System.out.println("请按要求输入");
        }
        menu();
    }

}
